{extends file="index.tpl"}
{block name="page-content"}

<script type="text/javascript">
$(document).ready(function()
{
	$(".edit_tr").click(function()
	{
		var ID=$(this).attr('id');
		$("#first_"+ID).hide();
		$("#gametype_"+ID).hide();
		$("#filetype_"+ID).hide();
		$("#device_"+ID).hide();
		$("#deviceid_"+ID).hide();
		
		$("#first_input_"+ID).show();
		$("#gametype_input_"+ID).show();
		$("#filetype_input_"+ID).show();
		$("#device_input_"+ID).show();
		$("#deviceid_input_"+ID).show();
	}).change(function()
	{
		var ID=$(this).attr('id');
		var first=$("#first_input_"+ID).val();
		var gametype=$("#gametype_input_"+ID).val();
		var filetype=$("#filetype_input_"+ID).val();
		var device=$("#device_input_"+ID).val();
		var deviceid=$("#deviceid_input_"+ID).val();
		
		var dataString = 'id='+ ID +'&gameLink='+first+'&gametype='+gametype+'&filetype='+filetype+'&device='+device+'&deviceid='+deviceid+'&database={if isset($data)}{$data}{else}tpg{/if}';
		
		$("#first_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#gametype_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#filetype_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#device_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
		$("#deviceid_"+ID).html('<img src="http://thanhphogame.com/admin/view/img/load.gif" />');
				
		if(first.length > 0)
		{
			$.ajax({
				type: "POST",
				url: 'http://thanhphogame.com/admin/controller/process/ajaxEditTableGameLink.php',
				data: dataString,
				cache: false,
				success: function(html)
				{
					$("#first_"+ID).html(first);
					$("#gametype_"+ID).html(gametype);
					$("#filetype_"+ID).html(filetype);
					$("#device_"+ID).html(device);
					$("#deviceid_"+ID).html(deviceid);
				}
			});
		}
		else
		{
			alert('Enter something.');
		}
	});
	
	$(".editbox").mouseup(function() {
		return false
	});
	
	$(document).mouseup(function(){
		$(".editbox").hide();
		$(".text").show();
	});

});
</script>

{literal}
<style>
	.editbox
	{
		display:none;
	}
	.editbox
	{
		font-size:14px;
		background-color:#ffffcc;
		border:solid 1px #000;
		padding:4px;
	}
	.edit_tr:hover
	{
		background:url(http://thanhphogame.com/admin/view/img/edit.png) right no-repeat #80C8E5;
		cursor:pointer;
	}

</style>
{/literal}
<div class="row-fluid">
    <div class="span12">
        <div class="block">
        	<div class="row-form">
        		
                <form method="POST" action="{$WEB_BASE_URL}/index.php?controller=gameLink&action=list&database={if isset($data)}{$data}{else}tpg{/if}&filter=filterParent">
					<div class="span3">
						<select name="filter" class="select" style="width: 100%;">
							<option value="0">-- Chọn Game Category--</option>
							{foreach from=$gameCategoryArr item=gameCategory}
							<option value="{$gameCategory.id}" {if isset($filter)}{if $gameCategory.id eq $filter}Selected{/if}{/if}>{$gameCategory.name}</option>	
							{/foreach}
							<option value="5"></option>
						</select>
					</div>&nbsp;&nbsp;&nbsp;
					<button class="btn btn-primary" type="submit">&nbsp;&nbsp;&nbsp;&nbsp;Fillter&nbsp;&nbsp;&nbsp;&nbsp;</button>
                </form>
			</div>
			<div class="btn-group" data-toggle="buttons-checkbox">
				<table>
					<tr>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=gameLink&action=list&database=tpg">
								<button type="submit" class="btn btn-primary {if isset($data) && $data eq 'tpg'}active{/if}">Thành Phố Game</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=gameLink&action=list&database=mmbg">
								<button type="submit" class="btn btn-primary {if isset($data) && $data eq 'mmbg'}active{/if}" >My Mobi Game</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=gameLink&action=list&database=mobile">
								<button type="submit" class="btn btn-primary {if isset($data) && $data eq 'mobile'}active{/if}" >Mobile</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=gameLink&action=add">
								<button type="submit" class="btn btn-warring" >Thêm Game Link</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=gameLink&action=addMMBG">
								<button type="submit" class="btn btn-warring" >Thêm Game Link MyMobiGame</button>
							</form>
						</td>
						<td>
							<form method="POST" action="{$WEB_BASE_URL}/index.php?controller=gameLink&action=addMobile">
								<button type="submit" class="btn btn-warring" >Thêm Game Link Mobile</button>
							</form>
						</td>
					</tr>
				</table>
			</div>
            <div class="head dblue">
                <div class="icon"><span class="ico-layout-9"></span></div>
                <h2>Danh Sách Game</h2>
                <ul class="buttons">
                    <li><a href="#" onClick="source('table_sort_pagination'); return false;">
                        <div class="icon"><span class="ico-info"></span></div>
                    </a></li>
                </ul>
            </div>
            <div class="data-fluid">
                <table class="table lcnp" id="listGame" cellpadding="0" cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            <th width="5%"><input type="checkbox" class="checkall" /></th>
                            <th width="5%">ID</th>
                            <th width="10%">Game Category</th>
                            <th width="10%">Is Game</th>
                            <th width="5%">Type</th>
                            <th width="10%">File Type</th>
                            <th width="10%">Device</th>
                            <th width="20%">Device Name</th>
                            <th width="15%">Link</th>
                            <th width="10%" class="TAC">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                   	{if isset($gameLinkArr)}
                    {foreach from=$gameLinkArr item=game}
                        <tr id="{$game.id}" class="edit_tr">
                            <td><input type="checkbox" name="order[]" value="528" /></td>
                            <td>{$game.id}</td>
                            <td>{if $game.game_category_id ge 1}{$game.category_name}{else}0{/if}</td>
                            <td>{if $game.game_id ge 1}{$game.game_name}{else}0{/if}</td>
                            <td>
                            	<span id="gametype_{$game.id}" class="text">
                            		{$game.type|substr:0:12}
                            	</span>
                            	<select name="type" class="editbox" id="gametype_input_{$game.id}" style="display: none;">
									<option value="JAVA" {if $game.type eq 'JAVA'}Selected{/if}>JAVA</option>
									<option value="ANDROID" {if $game.type eq 'ANDROID'}Selected{/if}>ANDROID</option>
									<option value="IOS" {if $game.type eq 'IOS'}Selected{/if}>IOS</option>
									<option value="WEB_GAME" {if $game.type eq 'WEB_GAME'}Selected{/if}>WEB_GAME</option>
									<option value="PC Windows" {if $game.type eq 'PC Windows'}Selected{/if}>PC Windows</option>
									<option value="TỰ ĐỘNG NHẬN DẠNG THIẾT BỊ" {if $game.type eq 'TỰ ĐỘNG NHẬN DẠNG THIẾT BỊ'}Selected{/if}>TỰ ĐỘNG NHẬN DẠNG THIẾT BỊ</option>
									<option value="QR CODE" {if $game.type eq 'QR CODE'}Selected{/if}>QR CODE</option>
								</select>
                            </td>
                            <td>
                            	<span id="filetype_{$game.id}" class="text">
                            		{$game.file_type}
                            	</span>
                            	<select name="file_type" class="editbox" id="filetype_input_{$game.id}" style="display: none;">
									<option value="JAD" {if $game.file_type eq 'JAD'}Selected{/if}>JAD</option>
									<option value="JAR" {if $game.file_type eq 'JAR'}Selected{/if}>JAR</option>
									<option value="APK" {if $game.file_type eq 'APK'}Selected{/if}>APK</option>
									<option value="IPA" {if $game.file_type eq 'IPA'}Selected{/if}>IPA</option>
									<option value="WEB" {if $game.file_type eq 'WEB'}Selected{/if}>WEB</option>
									<option value="TỰ ĐỘNG" {if $game.file_type eq 'TỰ ĐỘNG'}Selected{/if}>TỰ ĐỘNG</option>
									<option value="CÀI TỰ ĐỘNG" {if $game.type eq 'CÀI TỰ ĐỘNG'}Selected{/if}>CÀI TỰ ĐỘNG</option>
									<option value="ZIP" {if $game.file_type eq 'ZIP'}Selected{/if}>ZIP</option>
									<option value="IMG" {if $game.file_type eq 'IMG'}Selected{/if}>IMG</option>
								</select>
                            </td>
                            <td>
                            	<span id="device_{$game.id}" class="text">
                            		{$game.device}
                            	</span>
                            	<select name="file_type" class="editbox" id="device_input_{$game.id}" style="display: none;">
									<option value="ALL" {if $game.device eq 'ALL'}Selected{/if}>All</option>
									<option value="ONE" {if $game.device eq 'ONE'}Selected{/if}>ONE</option>
								</select>
                            </td>
                            <td>
                            	<span id="deviceid_{$game.id}" class="text">
                            		{if $game.device_id ge 1}{$game.device_name|substr:0:78}...{else}0{/if}
                            	</span>
                            	<select name="file_type" class="editbox" id="deviceid_input_{$game.id}" style="display: none;">
                            		<option value="0">-- Chọn Device --</option>	
									{foreach from=$deviceArr item=device}
										<option value="{$device.id}" {if $device.id eq $game.device_id}Selected{/if}>{$device.device_name}</option>
									{/foreach}
								</select>
                            </td>
                            <td class="edit_td" >
                            	<span id="first_{$game.id}" class="text">
                            		{$game.link}
                            	</span>
                            	<input type="text" value="{$game.link}" class="editbox" id="first_input_{$game.id}" style="display: none;"/>
                            </td>
                            <td>
                                <a href="{$WEB_BASE_URL}/index.php?controller=gameLink&action=update&database={if isset($data)}{$data}{else}tpg{/if}&id={$game.id}" class="button green">
                                    <div class="icon"><span class="ico-pencil"></span></div>
                                </a>
                                <a href="{$WEB_BASE_URL}/index.php?controller=gameLink&action=delete&database={if isset($data)}{$data}{else}tpg{/if}&id={$game.id}" class="button red" onclick="return confirm('Bạn có muốn xóa tiếp không?')">
                                    <div class="icon"><span class="ico-remove"></span></div>
                                </a>
                            </td>
                        </tr>
                    {/foreach}
                    {/if}
                    </tbody>
                </table>
                <div class="pagination pagination-centered">
                       {if isset($pageFirst) && isset($pagePrev) && isset($pageList) && isset($pageNext) && isset($pageLast)}
	                	<ul>
	                		<li class="disabled">{$pageFirst}</li>
	                		<li class="active">{$pagePrev}</li>
	                		<li>{$pageList}</li>
	                		<li>{$pageNext}</li>
	                		<li>{$pageLast}</li>
	                    </ul>
	                    {/if}
                    </div>
            </div>
        </div>
    </div>
</div>
<script>


{/block}
